package com.altio.swing.portlet;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;

public class PortletDockUI extends ComponentUI {
  
  private static PortletDockUI instance = null;

  public static ComponentUI createUI(PortletDock portletDock) {
    if(instance == null) {
      instance = new PortletDockUI();
    }
    
    return instance;
  }
  
  @Override
  public void installUI(JComponent c) {
    super.installUI(c);

    if(c instanceof PortletDock) {
      ((PortletDock)c).setGlueComponent(new JComponent() {
        @Override
        public boolean isOpaque() {
          return false;
        }

        @Override
        protected void paintComponent(Graphics g) {
          Graphics2D g2d = (Graphics2D) g;

          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

          g2d.setColor(Color.gray);
          // Initialise a dashed line
          float[] intervals = new float[] { 15 };
          g2d.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 50, intervals, 0));

          g2d.drawRoundRect(3, 3, getWidth() - 6, getHeight() - 6, 20, 20);

        }
      });
    }
  }

}
